<?php

namespace addons\kzvote\controller;

use addons\kzvote\library\WechatService;
use app\common\model\kzvote\Review as ReviewModel;

class Review extends Base
{
    protected $noNeedLogin = ['index'];

    public function save()
    {
        $user = $this->auth->getUser();
        $post             = $this->request->post();
        $vote             = \app\common\model\kzvote\Vote::get($post['vote_id']);
        $post['admin_id'] = $vote['admin_id'];
        $post['user_id'] = $user['id'];
        if ($this->platform == 'wxapp'){
            $service          = new WechatService();
            if (!$service->contentSecurity($post['content'])) {
                $this->error('内容含有违法违规文字');
            }
        }
        $model = new ReviewModel;
        if ($model->allowField(true)->save($post)) {
            $this->success('发送成功');
        }
        $this->error('发送失败');
    }

    /**
     * 随机查询弹屏
     */
    public function index()
    {
        $person_id = $this->request->request('person_id');
        $data      = (new ReviewModel)
            ->where('person_id', $person_id)
            ->orderRaw('rand()')
            ->limit(60)
            ->column('content');
        $this->success('',$data);
    }

}
